Skip to content

setup.py: check SHA-256 of the downloaded MuPDF tarball - #5332

Open
owen-alderson wants to merge 1 commit into
pymupdf:mainfrom
owen-alderson:check-mupdf-tgz-sha256
Open

owen-alderson wants to merge 1 commit into
pymupdf:mainfrom
owen-alderson:check-mupdf-tgz-sha256

Conversation

@owen-alderson

Copy link
Copy Markdown

Fixes #3463.

The default MuPDF source tarball (mupdf-{version_mupdf}-source.tar.gz) was downloaded and built without any integrity check, so a modified tarball, from a compromised server or a corrupted download, would be built silently.

This adds version_mupdf_sha256 next to version_mupdf, set to the SHA-256 that https://mupdf.com/releases lists for mupdf-1.28.6-source.tar.gz. get_mupdf_internal() checks it:

  • after downloading, before the file gets its final name, so a bad download is never reused;
  • when reusing a previously downloaded file; on a mismatch the file is removed and downloaded again.

Custom locations set with PYMUPDF_SETUP_MUPDF_TGZ (URL, git or local path) are not checked, so existing workflows are unchanged. The hash needs updating together with version_mupdf on each MuPDF upgrade.

Testing (Python 3.12, macOS), calling get_mupdf_internal('tgz') directly:

  • Default location with the real hash: downloads and passes.
  • Explicit URL with a wrong hash constant: not checked, passes.
  • Default location with a wrong hash constant: the cached file is rejected, and the fresh download raises SHA-256 mismatch ... expected 000…, got dc85000640a4… without being renamed into place.

I did not run a full source build.

AI assistance: written with Claude Code (claude-opus-5-5); I reviewed the change and the test results.

The default MuPDF .tar.gz was downloaded without any integrity check.
Hard-code its SHA-256 from https://mupdf.com/releases next to
version_mupdf and check it after downloading, and when reusing a
previously downloaded file. Custom locations from
PYMUPDF_SETUP_MUPDF_TGZ are not checked.

Fixes pymupdf#3463.

Assisted-by: Claude Code:claude-opus-5-5
@owen-alderson

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check the hash of the downloaded MuPDF tarball

1 participant